Some(path) => path.to_path_buf(),
None => exe.to_path_buf(),
};
- let mut process = try!(compile.target_process(exe, &root))
- .into_process_builder();
+ let mut process = try!(compile.target_process(exe, &root));
process.args(args).cwd(config.cwd());
try!(config.shell().status("Running", process.to_string()));
+++ /dev/null
-use std::collections::HashMap;
-use std::ffi::{OsStr, OsString};
-use std::fmt;
-use std::path::Path;
-
-use util::{CargoResult, ProcessBuilder, process};
-use util::Config;
-
-/// Prototype for a command that must be executed.
-#[derive(Clone)]
-pub struct CommandPrototype {
- ty: CommandType,
- builder: ProcessBuilder,
-}
-
-impl CommandPrototype {
- pub fn new(ty: CommandType, config: &Config)
- -> CargoResult<CommandPrototype> {
- Ok(CommandPrototype {
- builder: {
- let mut p = match ty {
- CommandType::Rustc => try!(config.rustc()).process(),
- CommandType::Rustdoc => process(&*try!(config.rustdoc())),
- CommandType::Target(ref s) |
- CommandType::Host(ref s) => process(s),
- };
- p.cwd(config.cwd());
- p
- },
- ty: ty,
- })
- }
-
- pub fn get_type(&self) -> &CommandType { &self.ty }
-
- pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut CommandPrototype {
- self.builder.arg(arg);
- self
- }
-
- pub fn args<T: AsRef<OsStr>>(&mut self, arguments: &[T]) -> &mut CommandPrototype {
- self.builder.args(arguments);
- self
- }
-
- pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut CommandPrototype {
- self.builder.cwd(path);
- self
- }
-
- pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T)
- -> &mut CommandPrototype {
- self.builder.env(key, val);
- self
- }
-
- pub fn get_args(&self) -> &[OsString] { self.builder.get_args() }
- pub fn get_cwd(&self) -> Option<&Path> { self.builder.get_cwd() }
-
- pub fn get_env(&self, var: &str) -> Option<OsString> {
- self.builder.get_env(var)
- }
-
- pub fn get_envs(&self) -> &HashMap<String, Option<OsString>> {
- self.builder.get_envs()
- }
-
- pub fn into_process_builder(self) -> ProcessBuilder {
- self.builder
- }
-}
-
-impl fmt::Display for CommandPrototype {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.builder.fmt(f)
- }
-}
-
-#[derive(Clone, Debug)]
-pub enum CommandType {
- Rustc,
- Rustdoc,
-
- /// The command is to be executed for the target architecture.
- Target(OsString),
-
- /// The command is to be executed for the host architecture.
- Host(OsString),
-}
use std::collections::{HashMap, HashSet};
-use std::ffi::OsStr;
+use std::ffi::{OsStr, OsString};
use std::path::PathBuf;
use semver::Version;
use core::{PackageId, Package, Target};
-use util::{self, CargoResult, Config};
-
-use super::{CommandType, CommandPrototype};
+use util::{self, CargoResult, Config, ProcessBuilder, process};
/// A structure returning the result of a compilation.
pub struct Compilation<'cfg> {
config: &'cfg Config,
}
+#[derive(Clone, Debug)]
+pub enum CommandType {
+ Rustc,
+ Rustdoc,
+
+ /// The command is to be executed for the target architecture.
+ Target(OsString),
+
+ /// The command is to be executed for the host architecture.
+ Host(OsString),
+}
+
impl<'cfg> Compilation<'cfg> {
pub fn new(config: &'cfg Config) -> Compilation<'cfg> {
Compilation {
}
/// See `process`.
- pub fn rustc_process(&self, pkg: &Package) -> CargoResult<CommandPrototype> {
+ pub fn rustc_process(&self, pkg: &Package) -> CargoResult<ProcessBuilder> {
self.process(CommandType::Rustc, pkg)
}
/// See `process`.
pub fn rustdoc_process(&self, pkg: &Package)
- -> CargoResult<CommandPrototype> {
+ -> CargoResult<ProcessBuilder> {
self.process(CommandType::Rustdoc, pkg)
}
/// See `process`.
pub fn target_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
- -> CargoResult<CommandPrototype> {
+ -> CargoResult<ProcessBuilder> {
self.process(CommandType::Target(cmd.as_ref().to_os_string()), pkg)
}
/// See `process`.
pub fn host_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
- -> CargoResult<CommandPrototype> {
+ -> CargoResult<ProcessBuilder> {
self.process(CommandType::Host(cmd.as_ref().to_os_string()), pkg)
}
/// The package argument is also used to configure environment variables as
/// well as the working directory of the child process.
pub fn process(&self, cmd: CommandType, pkg: &Package)
- -> CargoResult<CommandPrototype> {
+ -> CargoResult<ProcessBuilder> {
let mut search_path = vec![];
// Add -L arguments, after stripping off prefixes like "native=" or "framework=".
search_path.extend(util::dylib_path().into_iter());
let search_path = try!(util::join_paths(&search_path,
util::dylib_path_envvar()));
- let mut cmd = try!(CommandPrototype::new(cmd, self.config));
+ let mut cmd = match cmd {
+ CommandType::Rustc => try!(self.config.rustc()).process(),
+ CommandType::Rustdoc => process(&*try!(self.config.rustdoc())),
+ CommandType::Target(ref s) |
+ CommandType::Host(ref s) => process(s),
+ };
cmd.env(util::dylib_path_envvar(), &search_path);
if let Some(env) = self.extra_env.get(pkg.package_id()) {
for &(ref k, ref v) in env {
use super::job::Work;
use super::{fingerprint, Kind, Context, Unit};
-use super::CommandType;
+use super::compilation::CommandType;
/// Contains the parsed output of a custom build script.
#[derive(Clone, Debug, Hash)]
// package's library profile.
let profile = cx.lib_profile(unit.pkg.package_id());
let to_exec = to_exec.into_os_string();
- let mut p = try!(super::process(CommandType::Host(to_exec), unit.pkg, cx));
- p.env("OUT_DIR", &build_output)
- .env("CARGO_MANIFEST_DIR", unit.pkg.root())
- .env("NUM_JOBS", &cx.jobs().to_string())
- .env("TARGET", &match unit.kind {
- Kind::Host => cx.host_triple(),
- Kind::Target => cx.target_triple(),
- })
- .env("DEBUG", &profile.debuginfo.to_string())
- .env("OPT_LEVEL", &profile.opt_level)
- .env("PROFILE", if cx.build_config.release {"release"} else {"debug"})
- .env("HOST", cx.host_triple())
- .env("RUSTC", &try!(cx.config.rustc()).path)
- .env("RUSTDOC", &*try!(cx.config.rustdoc()));
-
- if let Some(links) = unit.pkg.manifest().links(){
- p.env("CARGO_MANIFEST_LINKS", links);
- }
+ let mut cmd = try!(super::process(CommandType::Host(to_exec), unit.pkg, cx));
+ cmd.env("OUT_DIR", &build_output)
+ .env("CARGO_MANIFEST_DIR", unit.pkg.root())
+ .env("NUM_JOBS", &cx.jobs().to_string())
+ .env("TARGET", &match unit.kind {
+ Kind::Host => cx.host_triple(),
+ Kind::Target => cx.target_triple(),
+ })
+ .env("DEBUG", &profile.debuginfo.to_string())
+ .env("OPT_LEVEL", &profile.opt_level)
+ .env("PROFILE", if cx.build_config.release { "release" } else { "debug" })
+ .env("HOST", cx.host_triple())
+ .env("RUSTC", &try!(cx.config.rustc()).path)
+ .env("RUSTDOC", &*try!(cx.config.rustdoc()));
+
+ if let Some(links) = unit.pkg.manifest().links() {
+ cmd.env("CARGO_MANIFEST_LINKS", links);
+ }
// Be sure to pass along all enabled features for this package, this is the
// last piece of statically known information that we have.
if let Some(features) = cx.resolve.features(unit.pkg.package_id()) {
for feat in features.iter() {
- p.env(&format!("CARGO_FEATURE_{}", super::envify(feat)), "1");
+ cmd.env(&format!("CARGO_FEATURE_{}", super::envify(feat)), "1");
}
}
}));
let data = &state.metadata;
for &(ref key, ref value) in data.iter() {
- p.env(&format!("DEP_{}_{}", super::envify(&name),
- super::envify(key)), value);
+ cmd.env(&format!("DEP_{}_{}", super::envify(&name),
+ super::envify(key)), value);
}
}
if let Some(build_scripts) = build_scripts {
- try!(super::add_plugin_deps(&mut p, &build_state,
+ try!(super::add_plugin_deps(&mut cmd, &build_state,
&build_scripts));
}
}
// And now finally, run the build command itself!
- state.running(&p);
- let cmd = p.into_process_builder();
+ state.running(&cmd);
let output = try!(cmd.exec_with_streaming(
&mut |out_line| { state.stdout(out_line); Ok(()) },
&mut |err_line| { state.stderr(err_line); Ok(()) },
use core::{PackageId, Target, Profile};
use util::{Config, DependencyQueue, Fresh, Dirty, Freshness};
-use util::{CargoResult, profile, internal};
+use util::{CargoResult, ProcessBuilder, profile, internal};
use super::{Context, Kind, Unit};
use super::job::Job;
-use super::command::CommandPrototype;
/// A management structure of the entire dependency graph to compile.
///
}
impl<'a> JobState<'a> {
- pub fn running(&self, cmd: &CommandPrototype) {
+ pub fn running(&self, cmd: &ProcessBuilder) {
let _ = self.tx.send((self.key, Message::Run(cmd.to_string())));
}
use core::{Package, PackageId, PackageSet, Target, Resolve};
use core::{Profile, Profiles, Workspace};
use core::shell::ColorConfig;
-use util::{self, CargoResult, human, machine_message};
+use util::{self, CargoResult, ProcessBuilder, human, machine_message};
use util::{Config, internal, ChainError, profile, join_paths, short_hash};
use self::job::{Job, Work};
use self::job_queue::JobQueue;
-pub use self::compilation::Compilation;
+pub use self::compilation::{Compilation, CommandType};
pub use self::context::{Context, Unit};
-pub use self::command::{CommandPrototype, CommandType};
pub use self::layout::{Layout, LayoutProxy};
pub use self::custom_build::{BuildOutput, BuildMap, BuildScripts};
-mod command;
mod compilation;
mod context;
mod custom_build;
}
state.running(&rustc);
- let process_builder = rustc.into_process_builder();
try!(if json_errors {
- process_builder.exec_with_streaming(
+ rustc.exec_with_streaming(
&mut |line| if !line.is_empty() {
Err(internal(&format!("compiler stdout is not empty: `{}`", line)))
} else {
},
).map(|_| ())
} else {
- process_builder.exec()
+ rustc.exec()
}.chain_error(|| {
human(format!("Could not compile `{}`.", name))
}));
// Add all relevant -L and -l flags from dependencies (now calculated and
// present in `state`) to the command provided
- fn add_native_deps(rustc: &mut CommandPrototype,
+ fn add_native_deps(rustc: &mut ProcessBuilder,
build_state: &BuildMap,
build_scripts: &BuildScripts,
pass_l_flag: bool,
// For all plugin dependencies, add their -L paths (now calculated and
// present in `state`) to the dynamic library load path for the command to
// execute.
-fn add_plugin_deps(rustc: &mut CommandPrototype,
+fn add_plugin_deps(rustc: &mut ProcessBuilder,
build_state: &BuildMap,
build_scripts: &BuildScripts)
-> CargoResult<()> {
fn prepare_rustc(cx: &Context,
crate_types: Vec<&str>,
- unit: &Unit) -> CargoResult<CommandPrototype> {
+ unit: &Unit) -> CargoResult<ProcessBuilder> {
let mut base = try!(process(CommandType::Rustc, unit.pkg, cx));
build_base_args(cx, &mut base, unit, &crate_types);
build_plugin_args(&mut base, cx, unit);
}
}
state.running(&rustdoc);
- rustdoc.into_process_builder().exec().chain_error(|| {
+ rustdoc.exec().chain_error(|| {
human(format!("Could not document `{}`.", name))
})
}))
}
fn build_base_args(cx: &Context,
- cmd: &mut CommandPrototype,
+ cmd: &mut ProcessBuilder,
unit: &Unit,
crate_types: &[&str]) {
let Profile {
}
-fn build_plugin_args(cmd: &mut CommandPrototype, cx: &Context, unit: &Unit) {
- fn opt(cmd: &mut CommandPrototype, key: &str, prefix: &str,
+fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &Context, unit: &Unit) {
+ fn opt(cmd: &mut ProcessBuilder, key: &str, prefix: &str,
val: Option<&OsStr>) {
if let Some(val) = val {
let mut joined = OsString::from(prefix);
opt(cmd, "-C", "linker=", cx.linker(unit.kind).map(|s| s.as_ref()));
}
-fn build_deps_args(cmd: &mut CommandPrototype, cx: &Context, unit: &Unit)
+fn build_deps_args(cmd: &mut ProcessBuilder, cx: &Context, unit: &Unit)
-> CargoResult<()> {
let layout = cx.layout(unit);
cmd.arg("-L").arg(&{
return Ok(());
- fn link_to(cmd: &mut CommandPrototype, cx: &Context, unit: &Unit)
+ fn link_to(cmd: &mut ProcessBuilder, cx: &Context, unit: &Unit)
-> CargoResult<()> {
for (filename, linkable) in try!(cx.target_filenames(unit)) {
if !linkable {
}
pub fn process(cmd: CommandType, pkg: &Package,
- cx: &Context) -> CargoResult<CommandPrototype> {
+ cx: &Context) -> CargoResult<ProcessBuilder> {
// When invoking a tool, we need the *host* deps directory in the dynamic
// library search path for plugins and such which have dynamic dependencies.
let mut search_path = util::dylib_path();
shell.status("Running", cmd.to_string())
}));
- if let Err(e) = cmd.into_process_builder().exec() {
+ if let Err(e) = cmd.exec() {
errors.push(e);
if !options.no_fail_fast {
break
try!(config.shell().verbose(|shell| {
shell.status("Running", p.to_string())
}));
- if let Err(e) = p.into_process_builder().exec() {
+ if let Err(e) = p.exec() {
errors.push(e);
if !options.no_fail_fast {
return Ok(errors);
pub use self::cargo_rustc::{compile_targets, Compilation, Layout, Kind, Unit};
pub use self::cargo_rustc::{Context, LayoutProxy};
pub use self::cargo_rustc::{BuildOutput, BuildConfig, TargetConfig};
-pub use self::cargo_rustc::{CommandType, CommandPrototype};
pub use self::cargo_run::run;
pub use self::cargo_install::{install, install_list, uninstall};
pub use self::cargo_new::{new, init, NewOptions, VersionControl};